<?php
/** .-------------------------------------------------------------------
 * |    Author: 熊伟洋 <chelious@foxmail.com>
 * |    WeChat: hello_McGrady
 * |           QQ: 434493420
 * |     Motto: Hungry & Humble
 * |---------------------------------------------------------------------
 * |    Copyright (c) 2012-2020, www.chelious.com. All Rights Reserved.
 * '-------------------------------------------------------------------*/

namespace system\model;

use hdphp\Model\Model;

class Tag extends Model
{
	//数据表
	protected $table = "tag";

	//允许填充字段
	protected $allowFill = [];

	//禁止填充字段
	protected $denyFill = [];

	//完整表名
	protected $full = false;

	//自动验证
	protected $validate = [
		//['字段名','验证方法','提示信息',验证条件,验证时间]
		['tname','required','您还没有填写内容哦',3,3],
		['tname','unique','标签重复了哟',3,3],
	];

	//自动完成
	protected $auto = [
		//['字段名','处理方法','方法类型',验证条件,验证时机]
	];

	//自动过滤
	protected $filter = [
		//[表单字段名,过滤条件,处理时间]
	];

	//时间操作,需要表中存在created_at,updated_at字段
	protected $timestamps = false;

	//添加标签
	public function add(){

		$tags = Q('post.tname');
		$tags = explode("|",$tags);		//此时返回值是一个数组
//		p($tags);
		$tag = new Tag();
		foreach($tags as $v){
			$tag['tname'] = $v;
			$tag->save();
		}
		return true;

	}

	//编辑标签
	public function edit(){
		$tid = Q('get.tid');
//		p($tid);
		$tag = Tag::find($tid);
//		p($tag);
		$tag['tname'] = Q('post.tname');
		return $tag->save();
	}

}